Page({
data: {
  region: ['广东省', '广州市', '从化区'],
  key:'b03052950bb249ef97eab77a8e048d40',//去官网复制你的key噢！
  locationId:'',
  weather:''
},
bindRegionChange: function (e) {
  console.log('picker发送选择改变，携带值为', e.detail.value)
  this.setData({
    region: e.detail.value
  })
  this.getLocationId()
},



getLocationId: function () {
  var that = this
  var key = this.data.key
  //调用该函数获取用户选的的地区
  wx.request({
      url: 'https://geoapi.qweather.com/v2/city/lookup?'+ 'location=' + this.data.region[2] + '&key=' + key,
    //如果请求成功
      success: function (res) {
        console.log(res.data.location[0].id)
        //把请求到的locationId赋值给data中的locationId
          that.setData({
              locationId: res.data.location[0].id
          })
          
          //调用获取天气的函数
          that.getWeather()
      }
  })
},
getWeather:function(){
  //获取指针
  var that = this
  //这是我们的和风天气复制过来的key
  //再复习一下，我们请求天气需要什么？ 1.key，2.城市名字（城市名字是通过picker选择的）=> locationid
  var key = that.data.key
  var locationId = that.data.locationId
  console.log("太好啦，我们已经有key--->" + key)
  console.log("太好啦，我们已经有--->" + locationId)
  //请求天气数据
  wx.request({
    url: 'https://devapi.qweather.com/v7/weather/now?' + 'location=' + locationId + '&key=' + key,
    //如果请求成功
    success: function (res) {
      //把请求到的天气数据赋值给data中的weather
      that.setData({
        weather: res.data.now
      })
      console.log(res.data.now)
    }
  })
},
 //页面加载
 onLoad:function(options){
  //每次打开页面调用这个函数然后获取从化区的天气
  this.getLocationId();
}

})
